"""测试配置"""

import pytest
import tempfile
import shutil
from pathlib import Path
from datetime import datetime

from file_organizer.models.config import Config, LLMConfig, UserPreferences, AppConfig
from file_organizer.utils.database import Database
from file_organizer.utils.config_manager import ConfigManager


@pytest.fixture
def temp_dir():
    """创建临时目录"""
    temp_path = Path(tempfile.mkdtemp())
    yield temp_path
    shutil.rmtree(temp_path, ignore_errors=True)


@pytest.fixture
def test_config():
    """测试配置"""
    llm_config = LLMConfig(
        default_provider="local",
        local_enabled=True,
        openai_enabled=False,
        request_timeout=10
    )
    
    user_prefs = UserPreferences(
        date_format="YYYY年MM月",
        auto_confirm=False
    )
    
    app_config = AppConfig(
        window_size=[800, 600],
        backup_enabled=False
    )
    
    return Config(
        llm=llm_config,
        user_preferences=user_prefs,
        app=app_config
    )


@pytest.fixture
def test_database(temp_dir):
    """测试数据库"""
    db_path = temp_dir / "test.db"
    return Database(db_path)


@pytest.fixture
def test_config_manager(temp_dir):
    """测试配置管理器"""
    return ConfigManager(temp_dir)


@pytest.fixture
def sample_files(temp_dir):
    """创建示例文件"""
    files = []
    
    # 创建不同类型的测试文件
    test_files = [
        "Python数据分析教程.pdf",
        "会议纪要-2024年项目启动.docx",
        "假期照片001.jpg",
        "项目代码.py",
        "数据表格.xlsx"
    ]
    
    for filename in test_files:
        file_path = temp_dir / filename
        file_path.touch()
        files.append(file_path)
    
    return files


@pytest.fixture
def sample_workspace_path(temp_dir):
    """创建示例工作空间目录结构"""
    workspace_path = temp_dir / "test_workspace"
    workspace_path.mkdir()
    
    # 创建目录结构
    dirs = [
        "工作文档/项目A",
        "工作文档/会议记录",
        "学习资料/编程/Python",
        "个人文件/照片",
        "其他"
    ]
    
    for dir_path in dirs:
        (workspace_path / dir_path).mkdir(parents=True)
    
    return workspace_path